package com.example.q_kang.hhh.home;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.bulong.rudeness.RudenessScreenHelper;
import com.example.q_kang.hhh.R;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.base.MVPActivity;
import com.sskj.base.adapter.slimadapter.IViewInjector;
import com.sskj.base.adapter.slimadapter.SlimAdapter;
import com.sskj.base.adapter.slimadapter.SlimInjector;
import com.sskj.base.bean.BuyDakuanListBean;
import com.sskj.base.bean.TeamJiHuoListBean;
import com.sskj.base.mvchelper.ModelRx2DataSource;
import com.sskj.base.utils.DateUtil;
import com.sskj.base.view.DividerLineItemDecoration;
import com.sskj.base.view.ToolBarLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Flowable;

/**
 * @author Hey
 * Create at  2019/04/11
 */
public class JiHuoRecordActivity extends MVPActivity<JiHuoRecordPresenter> {

    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter<TeamJiHuoListBean> slimAdapter;
    private MVCCoolHelper<List<TeamJiHuoListBean>> mvcHelper;

    @Override
    public int getLayoutId() {
        return R.layout.activity_ji_hu_orecord;
    }

    @Override
    public JiHuoRecordPresenter getPresenter() {
        return new JiHuoRecordPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setDividerColor(ContextCompat.getColor(this, R.color.divider_s))
                .setLeftPadding((int) RudenessScreenHelper.pt2px(this, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(this, 30))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(this, 1))
                .setFirstDraw(false)
                .setLastDraw(false));
        slimAdapter = SlimAdapter.create().register(R.layout.item_jihuo, new SlimInjector<TeamJiHuoListBean>() {
            @Override
            public void onInject(TeamJiHuoListBean data, IViewInjector injector) {
                injector.text(R.id.tv_account, data.getAccount())
                        .text(R.id.tv_date, DateUtil.getDateFormat(Long.valueOf(data.getReg_time()) * 1000, DateUtil.PATTERN_J));

            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        ModelRx2DataSource<TeamJiHuoListBean> dataSource = new ModelRx2DataSource<>(
                (ModelRx2DataSource.OnLoadSource<TeamJiHuoListBean>)
                        page -> mPresenter.getTeamJiHuo(page), 10);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, JiHuoRecordActivity.class);
        context.startActivity(intent);
    }
}
